//
//  JZHomeViewController.swift
//  SwiftWeibo
//
//  Created by Stone on 16/12/2.
//  Copyright © 2016年 Stone. All rights reserved.
//

import UIKit

//定义全局常量, 尽量使用private修饰
private let cellId = "cellId"

class JZHomeViewController: JZBaseViewController {

    //创建一个数组用来接收数据 : 
    lazy var weiBoList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func loadData() {
        //模拟延时加载数据 -> dispatch_after
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
            
            for i in 0..<15 {
                if self.isPullup {
                    self.weiBoList.append("上拉+\(i)")
                }else {
                    self.weiBoList.insert(i.description, at: 0)
                }
            }
            
            self.isPullup = false
            self.tableView?.reloadData()
        }
        
    }
    
    func showFriends() {
        print("显示好友")
        let vc = JZDemoViewController()
//        vc.hidesBottomBarWhenPushed = true
        //push 的动作是nav做的
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
}

// MARK: - 表格数据源方法
extension JZHomeViewController {
    
    
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return weiBoList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = weiBoList[indexPath.row]
        return cell
        
    }
}

// MARK: - 设置界面
extension JZHomeViewController {
    //重写父类的方法
    override func setUpTableView() {
        super.setUpTableView()
        //设置导航栏按钮
        //        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(showFriends))
        
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        //注册原型cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
    
}
